001 /* $RCSfile: DES1KeySecretKeyFactoryEngine.java,v $ 002 * $Revision: 1.9 $ 003 * $Date: 2003/10/04 19:18:38 $ 004 * $Author: uwe_guenther $ 005 * $State: Exp $ 006 * 007 * Created on August 13, 2001 9:45 PM 008 * 009 * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de> 010 * 011 * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE- 012 * ServiceProvider is a library, written in JavaTM, that should be 013 * used in HBCI banking applications (clients and may be servers), 014 * to do cryptographic operations. 015 * 016 * The jhbci library is free software; you can redistribute it and/or 017 * modify it under the terms of the GNU Lesser General Public 018 * License as published by the Free Software Foundation; either 019 * version 2.1 of the License, or (at your option) any later version. 020 * 021 * The jhbci library is distributed in the hope that it will be useful, 022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 024 * Lesser General Public License for more details. 025 * 026 * You should have received a copy of the GNU Lesser General Public 027 * License along with this library; if not, write to the Free Software 028 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 029 * 030 */ 031 032 package de.cscc.crypto.provider; 033 034 import java.security.InvalidKeyException; 035 import java.security.spec.InvalidKeySpecException; 036 import java.security.spec.KeySpec; 037 038 import javax.crypto.SecretKey; 039 import javax.crypto.SecretKeyFactorySpi; 040 041 042 /** 043 * DES1KeySecretKeyFactoryEngine Class. 044 * 045 * @author <a href=mailto:uwe@cscc.de>Uwe Günther</a> 046 * @version $Revision: 1.9 $ 047 */ 048 public final class DES1KeySecretKeyFactoryEngine extends SecretKeyFactorySpi { 049 050 /** The delegate for this wrapper object */ 051 private DES1KeySecretKeyFactoryImpl factory = 052 new DES1KeySecretKeyFactoryImpl(); 053 054 /** 055 * Creates new DES1KeySecretKeyFactoryEngine. 056 * 057 * @throws SecurityException if the provider self integrity check fails. 058 */ 059 public DES1KeySecretKeyFactoryEngine() { 060 if (JHBCI.selfIntegrityChecking() == false) { 061 throw new SecurityException("JHBCI-Provider is tampered."); 062 } 063 } 064 065 /** 066 * Returns a string representation of the object. 067 * 068 * @return a string representation of the object. 069 */ 070 public String toString() { 071 return this.factory.toString(); 072 } 073 074 /** 075 * Generates a <code>SecretKey</code> object from the 076 * provided key specification (key material). 077 * 078 * @param keySpec the specification (key material) of the secret key. 079 * @return the secret key. 080 * @throws NullPointerException if keySpec is null. 081 * @throws InvalidKeySpecException if the given key specification 082 * is inappropriate for this secret-key factory to produce a secret key. 083 */ 084 protected SecretKey engineGenerateSecret(KeySpec keySpec) 085 throws InvalidKeySpecException { 086 return this.factory.generateSecret(keySpec); 087 } 088 089 090 /** 091 * Returns a specification (key material) of the given key object in the 092 * requested format. 093 * 094 * @param key the key. 095 * @param keySpec the requested format in which the key material shall be 096 * returned. 097 * @return the underlying key specification (key material) in the requested 098 * format. 099 * @throws NullPointerException if key or keySpec is null. 100 * @throws InvalidKeySpecException if the requested key specification is 101 * inappropriate for the given key (e.g., the algorithms associated with 102 * <code>key</code> and <code>keySpec</code> do not match, or 103 * <code>key</code> references a key on a cryptographic hardware device 104 * whereas <code>keySpec</code> is the specification of a software-based 105 * key), or the given key cannot be dealt with (e.g., the given key has 106 * an algorithm or format not supported by this secret-key factory). 107 */ 108 protected KeySpec engineGetKeySpec(SecretKey key, Class keySpec) 109 throws InvalidKeySpecException { 110 return this.factory.getKeySpec(key, keySpec); 111 } 112 113 /** 114 * Translates a key object, whose provider may be unknown or potentially 115 * untrusted, into a corresponding key object of this secret-key factory. 116 * 117 * @return they key whose provider is unknown or untrusted. 118 * @param key the key whose provider is unknown or untrusted. 119 * @throws NullPointerException if key is null. 120 * @throws InvalidKeyException if the given key cannot be processed by this 121 * secret-key factory. 122 */ 123 protected SecretKey engineTranslateKey(SecretKey key) 124 throws InvalidKeyException { 125 return this.factory.translateKey(key); 126 } 127 128 }